package servlet;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.EmailingSystem;
import model.PollImpl;
import model.PollUserImpl;
import bean.Poll;
import bean.PollUser;

public class AssignPollServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 254130936276944026L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost (request, response);
	}
	
	public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		response.setCharacterEncoding("GBK");
		System.out.println("----------- doPost run!");
		//String username = request.getParameter("pmusername");
		System.out.println(request.getParameter("pollid"));
		int pollid = Integer.parseInt(request.getParameter("pollid"));
		
		//PollUser user = new PollUser();
		//user.setUsername(username);
		//PollUserImpl.setUserAttributes(user);
		System.out.println("---------- After get parameters");
		Poll p = new Poll();
		p.setId(pollid);
		PollImpl.setPollAttributes(p);
		System.out.println("After setup poll bean");
		
		EmailingSystem.sendInformativeEmail(p);

		System.out.println("After send informative email");
		String forward = "../success.jsp";

		RequestDispatcher rd=request.getRequestDispatcher(forward);
		rd.forward(request, response);
	}


}
